package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    // 插入订单数据
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 获取订单的分页数据
     * @param ordersPageQuery
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQuery);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     * @return
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer count(Integer status);

    /**
     *
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    /**
     * 根据订单号查询订单id
     * @param orderNumber
     * @return
     */
    @Select("select id from orders where number = #{orderNumber}")
    Object getByorderId(String orderNumber);

    /**
     * 统计指定时间区间内每天的营业额数据
     * @return
     */
    Double getSumAmount(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    // 统计指定时间区间内订单数量
    Integer countOrders(Map<String, Object> map);


}
